package com.base.cn.platform.os.common.utils.result;

import com.base.cn.platform.os.common.utils.BaseUtil;
import com.base.cn.platform.os.common.utils.ObjectUtils;

import java.util.HashMap;
import java.util.Map;
/**
 * 返回结果工具类
 *
 * @author s.li
 * @create 2018-02-06 14:38
 */
public class ResultUtil extends BaseUtil {
    public static final Map<String,Object> SUCCESS(){
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("success",true);
        resultMap.put("message","操作成功");
        resultMap.put("entity",null);
        return resultMap;
    }

    public static final Map<String,Object> SUCCESS(Object dataObj){
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("success",true);
        resultMap.put("message","操作成功");
        resultMap.put("entity",dataObj);
        return resultMap;
    }

    public static final Map<String,Object> SUCCESS(String message){
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("success",true);
        resultMap.put("message",message);
        resultMap.put("entity",null);
        return resultMap;
    }

    public static final Map<String,Object> SUCCESS(String message,Object dataObj){
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("success",true);
        resultMap.put("message",message);
        resultMap.put("entity",dataObj);
        return resultMap;
    }

    public static final Map<String,Object> ERROR(){
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("success",false);
        resultMap.put("message","系统错误，操作失败");
        resultMap.put("entity",null);
        return resultMap;
    }

    public static final Map<String,Object> ERROR(String message,Object entity){
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("success",false);
        resultMap.put("message",message);
        resultMap.put("entity",entity);
        return resultMap;
    }

    public static final Map<String,Object> ERROR(String message){
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("success",false);
        resultMap.put("message",message);
        resultMap.put("entity",null);
        return resultMap;
    }

    public static final Map<String,Object> to(Map<String,Object> resultMap,boolean success,String message,Object entity){
        resultMap.put("message",message);
        resultMap.put("entity",entity);
        resultMap.put("success",success);
        return resultMap;
    }

    public static final Map<String,Object> to(Map<String,Object> resultMap,String message,Object entity){
        resultMap.put("message",message);
        resultMap.put("entity",entity);
        return resultMap;
    }

    public static final Map<String,Object> to(Map<String,Object> resultMap,Object entity){
        resultMap.put("entity",entity);
        return resultMap;
    }

    public static final Object getEntity(Map<String,Object> resultMap){
        if(ObjectUtils.isNotEmpty(resultMap)){
            return resultMap.get("entity");
        }
        return null;
    }
    public static final void setEntity(Map<String,Object> resultMap,Object entity){
        resultMap.put("entity",entity);
    }

    public static final void setSuccess(Map<String,Object> resultMap,boolean success){
        resultMap.put("success",success);
    }

    public static final boolean getSuccess(Map<String,Object> resultMap){
        if(ObjectUtils.isNotEmpty(resultMap)){
            return (boolean) resultMap.get("success");
        }
        return false;
    }

    public static final void setMessage(Map<String,Object> resultMap,String message){
        resultMap.put("message",message);
    }

    public static final String getMessage(Map<String,Object> resultMap){
        if(ObjectUtils.isNotEmpty(resultMap)){
            return (String) resultMap.get("message");
        }
        return null;
    }

    public static final void removeEntity(Map<String,Object> resultMap){
        if(ObjectUtils.isNotEmpty(resultMap)){
            resultMap.remove("entity");
        }
    }

}
